package com.woniu.day8.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.day8.pojo.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface UserRoleMapper extends BaseMapper<Role> {

    /**
     * 删除用户的所有角色关联
     * @param userId 用户ID
     */
    @Delete("DELETE FROM t_user_role WHERE uid = #{userId}")
    void deleteUserAllRolesByUserId(@Param("userId") Integer userId);

    /**
     * 为用户添加角色关联
     * @param userId 用户ID
     * @param roleId 角色ID
     */
    @Insert("INSERT INTO t_user_role (uid, rid) VALUES (#{userId}, #{roleId})")
    void insertUserRole(@Param("userId") Integer userId, @Param("roleId") Integer roleId);
}
